package cn.kk.controller;

import cn.kk.base.model.BaseController;
import cn.kk.model.user.entity.UserInfoEntity;
import cn.kk.service.UserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * @Author: kk
 * @Date: 2022/11/14  22:41
 * @Version 1.0
 */
@RequestMapping("/user/api/info")
@RestController
@Tag(name = "用户信息服务-api")
public class UserInfoApiController extends BaseController {

    @Resource
    private UserInfoService userInfoService;

    @Operation(summary = "验重")
    @GetMapping("/checkRepeat")
    public boolean checkRepeat(@RequestParam(value = "phone", required = false) String phone,
                               @RequestParam(value = "email", required = false) String email) {
        return userInfoService.checkRepeat(phone, email);
    }

    @Operation(summary = "新增用户")
    @PostMapping("/save")
    public boolean save(@RequestBody UserInfoEntity userInfo) {
        return userInfoService.save(userInfo);
    }

    @Operation(summary = "根据手机/邮箱查询用户")
    @GetMapping("/search")
    public UserInfoEntity search(@RequestParam(value = "account") String account) {
        return userInfoService.search(account);
    }

    @Operation(summary = "根据id查询用户")
    @GetMapping("/getUser/{id}")
    public UserInfoEntity getUser(@PathVariable("id") Serializable id) {
        return userInfoService.getById(id);
    }

}
